#ifndef VIEWAREA_H
#define VIEWAREA_H

#include <QWidget>

#include "navigationmode.h"
#include "viewsplit.h"
class QLayout;
class QSplitter;

namespace stitch
{
class ViewWindow;
// Hold a list of ViewWindow. A ViewSplit could display any ViewWorkspace.
// A ViewWorkspace could only be displayed by one ViewSplit at a time.
// If a ViewWorkspace is visible, it is managed by its ViewSplit and
// its state may not reflect the real fact.
struct ViewWorkspace
{
    explicit ViewWorkspace(ID p_id)
        : m_id(p_id)
    {
    }

    ~ViewWorkspace()
    {
        Q_ASSERT(m_viewWindows.isEmpty());
    }

    void clear()
    {
        m_visible = false;
        m_viewWindows.clear();
        m_currentViewWindowIndex = 0;
    }

    const ID m_id = 0;

    // Whether it is displayed by a ViewSplit now.
    bool m_visible = false;

    QVector<ViewWindow *> m_viewWindows;

    int m_currentViewWindowIndex = 0;
};
// ViewArea -- ViewSplit -- ViewWindow.
// ViewSplit may be put within a splitter.
// There may be multiple ViewWindow for the same buffer.
class ViewArea : public QWidget, public NavigationMode
{
    Q_OBJECT
public:
    explicit ViewArea(QWidget *p_parent = nullptr);

    ~ViewArea();

    QSize sizeHint() const Q_DECL_OVERRIDE;

    ViewWindow *getCurrentViewWindow() const;

    // NavigationMode.
protected:
    QVector<void *> getVisibleNavigationItems() Q_DECL_OVERRIDE;

    void placeNavigationLabel(int p_idx, void *p_item, QLabel *p_label) Q_DECL_OVERRIDE;

    void handleTargetHit(void *p_item) Q_DECL_OVERRIDE;

    void clearNavigation() Q_DECL_OVERRIDE;

protected:
    // To accept specific drop.
    void dragEnterEvent(QDragEnterEvent *p_event) Q_DECL_OVERRIDE;

    // Drop the data.
    void dropEvent(QDropEvent *p_event) Q_DECL_OVERRIDE;

private:
    enum class SplitType
    {
        Vertical,
        Horizontal
    };

    void setupUI();
     void setupShortcuts();
    ViewSplit *getCurrentViewSplit() const;
    void setCurrentViewSplit(ViewSplit *p_split, bool p_focus);

    QVector<ViewSplit::ViewWindowNavigationModeInfo> m_navigationItems;
    QVector<ViewSplit *> m_splits;
    QLayout *m_mainLayout = nullptr;
    ViewSplit *m_currentSplit = nullptr;

    ViewWindow *m_currentWindow = nullptr;
};
}
#endif // VIEWAREA_H
